package com.gavel.parser;

import com.gavel.utils.StringUtils;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class SkuItem {

    private String url;

    // 主图片
    private final List<Pic> productPics = new ArrayList<>();

    // 详情图片
    private final List<Pic> detailPics = new ArrayList<>();

    // 属性
    private final Map<String, String> attrs = new LinkedHashMap<>();

    // 产品描述
    private final List<String> desc = new ArrayList<>();

    private String code;       // 编码

    private String type;       // 类型

    private String title;       // 标题

    private String product;       // 产品(系列)

    private String category;    // 类目

    private String categoryDesc;    // 类目描述

    private String  brand;      // 品牌

    private String  brandEn;      // 品牌

    private float salesPrice;   // 售价

    private float originalPrice;   // 原价

    private String  unit;      // 计量单位

    private String model;   // 制造商型号

    private String fahuori;   // 发货日

    private String intro;

    private List<String> categories;   // 多级类目

    public SkuItem() {
    }

    public SkuItem(String url) {
        this.url = url;
    }

    public String getUrl() {
        return url;
    }

    public void addDetailPic(int pos, String url) {
        detailPics.add(new Pic(pos, url));
    }

    public void addProductPic(int pos, String url) {
        productPics.add(new Pic(pos, url));
    }

    public void addProductPic(int pos, String url,  String original) {
        productPics.add(new Pic(pos, url, original));
    }

    public void addAttr(String name, String value) {
        attrs.put(name, value);
    }

    public String attr(String name) {
        if (StringUtils.isBlank(name)) {
            return "";
        }
        if ( attrs.containsKey(name) ) {
            return attrs.get(name);
        }
        return "";
    }

    public void addDetail(String text) {
        desc.add(text);
    }

    public List<Pic> getProductPics() {
        return productPics;
    }

    public List<Pic> getDetailPics() {
        return detailPics;
    }

    public Map<String, String> getAttrs() {
        return attrs;
    }

    public List<String> getDesc() {
        return desc;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String getBrandEn() {
        return brandEn;
    }

    public void setBrandEn(String brandEn) {
        this.brandEn = brandEn;
    }

    public float getSalesPrice() {
        return salesPrice;
    }

    public void setSalesPrice(float salesPrice) {
        this.salesPrice = salesPrice;
    }

    public float getOriginalPrice() {
        return originalPrice;
    }

    public void setOriginalPrice(float originalPrice) {
        this.originalPrice = originalPrice;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public String getCategoryDesc() {
        return categoryDesc;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getType() {
        return type;
    }

    public String getProduct() {
        return product;
    }

    public void setProduct(String product) {
        this.product = product;
    }

    public void setCategoryDesc(String categoryDesc) {
        this.categoryDesc = categoryDesc;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getFahuori() {
        return fahuori;
    }

    public void setFahuori(String fahuori) {
        this.fahuori = fahuori;
    }

    public String getIntro() {
        return intro;
    }

    public void setIntro(String intro) {
        this.intro = intro;
    }

    public List<String> getCategories() {
        return categories;
    }

    public void setCategories(List<String> categories) {
        this.categories = categories;
    }

    public static class Pic {

        private final int pos;

        private final String url;

        private final String original;

        public Pic(int pos, String url) {
            this(pos, url, url);
        }

        public Pic(int pos, String url, String original) {
            this.pos = pos;
            this.url = url;
            this.original = original;
        }

        public int getPos() {
            return pos;
        }

        public String getUrl() {
            return url;
        }

        public String getOriginal() {
            return original;
        }

        @Override
        public String toString() {
            return "Pic{" +
                    "pos=" + pos +
                    ", url='" + url + '\'' +
                    '}';
        }
    }

}
